﻿//Copyright 2010 http://tv4home.codeplex.com
//This file is part of TV4Home.WebInterface.UI.
//TV4Home.WebInterface.UI is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
//TV4Home.WebInterface.UI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//You should have received a copy of the GNU General Public License along with TV4Home.WebInterface.UI If not, see http://www.gnu.org/licenses/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using TV4Home.Server.TVEInteractionLibrary.Interfaces;

namespace TV4Home.WebInterface.UI.Code
{
    public static class Utils
    {
        public static class Misc
        {
            public static string WebsiteVersion
            {
                get
                {
                    return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
                }
            }
        }

        public static string GetChannelLogoPath(WebChannelBasic channel)
        {
            string channelName = channel.DisplayName;

            // fix up path
            foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                channelName = channelName.Replace(c.ToString(), "");

            return "~/style/images/TVGuide/logos/" + channelName + ".png";
        }

        public static string GetYesNoFromBoolean(bool value)
        {
            return value ? Properties.Resources.YesString : Properties.Resources.NoString;
        }

        /// <summary>
        /// Kills the whole process-tree of a given process. This means that the process and all processes started by this process will be killed.
        /// </summary>
        /// <param name="processIdToKill">The process-id of the process whose tree should be killed.</param>
        public static void KillProcessTree(int processIdToKill)
        {
            System.Diagnostics.Process.Start("taskkill", "/F /T /PID " + processIdToKill).WaitForExit(5000);
        }
    }
}
